﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Wedo.Recognition.Domain;
using Wedo.Mvc.Utility;
using Wedo.Recognition.Domain;
using Wedo.Utility.Reflection;
using Wedo.Recognition.Service.Service;
using Wedo.Mvc.Utility.Common; 
using Wedo.Recognition.Domain.Models; 

namespace Wedo.Recognition.Service
{
    public class BindDropDownList
    {
        #region 数据库查询
        
        /// <summary>
        /// 用户名
        /// </summary>
        /// <param name="ad"></param>
        /// <returns></returns>
        public static string GetUserName(string ad)
        {
            var unityWork = Container_Config.GetIUnitWork();
            var model = unityWork.User.GetByName(ad);
            if (model != null)
                return model.StaffNameEN;
            else
            {
                return ad;
            }
        }

        //public static string GetRoleName(int value)
        //{
        //    return XmlRoles.GetInstance().GetName(value);
        //}

        //public static IEnumerable<SelectListItem> GetRoles()
        //{
        //    return XmlRoles.GetInstance().GetSelect();
        //}


        public static List<SelectListItem> GetBankList()
        {
            var dbContext = Container_Config.GetIUnitWork();
            List<SelectListItem> list = dbContext.CacheSet<Bank>().All()
                .Select(m => new SelectListItem { Text = m.BankName + "--" + m.Currency, Value = m.BankCode }).ToList();
            return list;
        }

        public static string GetBankName(string bankCode)
        {
            var dbContext = Container_Config.GetIUnitWork();
            var bankItem = dbContext.CacheSet<Bank>().Filter(s => s.BankCode == bankCode).FirstOrDefault();
            if (bankItem != null)
                return bankItem.BankName;
            return string.Empty;
        }

        //public static List<SelectListItem> GetHRDepartment()
        //{
        //    EFDbContext dbContext = new EFDbContext();

        //    CustomerService service = new CustomerService();
        //    return service.GetHRDepartMent().Select(m => new SelectListItem { Text = m, Value = m }).ToList();

        //}


        //public static IEnumerable<SelectListItem> GetParamList(int type,string val="")
        //{
        //    var dbContext = Container_Config.GetIUnitWork();
        //    SysParamService service = new SysParamService(dbContext);

        //    var list= service.GetList(type);
        //    foreach (var item in list)
        //    {
        //        if (item.Value == val)
        //            item.Selected = true;
        //    }
        //    return list;
        //}

        //public static string GetParamListName(int type, string code)
        //{
        //    var dbContext = Container_Config.GetIUnitWork();
        //    SysParamService service = new SysParamService(dbContext);

        //    return service.GetText(code, type);
        //}

        //public static string GetParamListName(string id) {
        //    var dbContext = Container_Config.GetIUnitWork();
        //    SysParamService service = new SysParamService(dbContext);
        //    return service.GetText(id);
        //}

        public static string GetParamListName(string parent, string value)
        {
            var dbContext = Container_Config.GetIUnitWork();
            SysParamService service = new SysParamService(dbContext);
            return service.GetText(parent,value);
        }

        #endregion

        #region 枚举

        /// <summary>
        /// 处理状态
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<SelectListItem> GetApprovaStates()
        {
            return SelectListHelper.GenerateListFromEnum<ApprovalStatus, int>();
        }

        /// <summary>
        /// 处理状态解释
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string ApprovalName(int state)
        {
            return EnumHelper<ApprovalStatus, int>.GetDescription(state);
        }

        /// <summary>
        /// 账单状态
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<SelectListItem> GetBankStatus()
        {
            return SelectListHelper.GenerateListFromEnum<BDStatus, int>();
        }

        /// <summary>
        /// 状态状态解释
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string GetBankStatusName(int state)
        {
            return EnumHelper<BDStatus, int>.GetDescription(state);
        }

        /// <summary>
        /// 收款类型
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<SelectListItem> GetReceiveTypes()
        {
            return SelectListHelper.GenerateListFromEnum<BDReceiveType, int>();
        }

        /// <summary>
        /// 收款类型解释
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string GetReceiveTypeName(int state)
        {
            return EnumHelper<BDReceiveType, int>.GetDescription(state);
        }

        /// <summary>
        /// 导入的文件类型
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<SelectListItem> GetImportTypes()
        {
            return SelectListHelper.GenerateListFromEnum<ImportType, int>();
        }

        /// <summary>
        /// 生成状态解释
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public static string GetCreateReceiveStatusName(int state)
        {
            return EnumHelper<CreateReceiveStatus, int>.GetDescription(state);
        }

        #endregion


    }
}